package com.ssh.dao.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;

import com.ssh.dao.UserDao;
import com.ssh.entity.Category;
import com.ssh.entity.Commodity;
import com.ssh.entity.User;

/**
 * DAO层 专做数据库增删改查操作
 * @author Administrator
 *
 */
@Repository
public class UserDaoImpl implements UserDao{
	
	@Autowired
	private HibernateTemplate ht;

	/**
	 * 执行HQL语句
	 */
	@SuppressWarnings("unchecked")
	public User loadUserByName(String userName) {
		List<User> list = ht.find("from User where userName=?", userName);
		if(null != list && list.size() > 0) {
			return list.get(0);
		}
		return null;
	}
	
	/**
	 * 通过parentid查询该栏目的所有子栏目
	 * @param parentid
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<Category> findCategorysByParentid(int parentid){
		List<Category> list = ht.find("from Category where parentid=?", parentid);
		return list;
	}
	public List<Commodity> findCommoditysByC3id(int c3id){
		List<Commodity> list= ht.find("form Commodity where c3id=?",c3id); 
		
		return list;
		
	}
	
	

}
